﻿using Framework.Core.Enums;
using Framework.SqlSugarCore.Repositories;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using my.abp.Application.Contracts.Dtos.Dict;
using my.abp.Application.Contracts.IServices.Dict;
using my.abp.Domain.IManagers.Dict;
using my.abp.Domain.Shared.Entities;
using my.abp.Domain.Shared.Enums;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace my.abp.Application.Services.Dict
{
	public class SysDictDataService : ApplicationService, ISysDictDataService
	{
		private readonly ISysDictDataManager _sysDictDataManager;
		private readonly ISysDictTypeManager _sysDictTypeManager;
		public SysDictDataService(ISysDictDataManager sysDictDataManager, ISysDictTypeManager sysDictTypeManager)
		{
			_sysDictDataManager = sysDictDataManager;
			_sysDictTypeManager = sysDictTypeManager;
		}

		/// <summary>
		/// 获取字典值分页列表
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("获取字典值分页列表")]
		public async Task<PagedResultDto<SysDictData>> Page(PageDictDataInput input)
		{
			RefAsync<int> total = 0;
			var outPut = await _sysDictDataManager.GetList(input.DictTypeId, input.Value, input.Code, input.SkipCount, input.MaxResultCount, total);

			var result = new PagedResultDto<SysDictData>();
			result.Items = outPut;
			result.TotalCount = total;
			return result;
		}

		/// <summary>
		/// 获取字典值列表
		/// </summary>
		/// <returns></returns>
		[DisplayName("获取字典值列表")]
		public async Task<List<SysDictData>> GetList([FromQuery] GetDataDictDataInput input)
		{
			return await _sysDictDataManager.GetDictDataListByDictTypeId(input.DictTypeId);
		}

		/// <summary>
		/// 增加字典值 
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("增加字典值")]
		public async Task<bool> AddDictData(AddDictDataInput input)
		{
			return await _sysDictDataManager.AddDictData(input.Adapt<SysDictData>());
		}

		/// <summary>
		/// 更新字典值
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("更新字典值")]
		public async Task UpdateDictData(UpdateDictDataInput input)
		{
			await _sysDictDataManager.UpdateDictData(input.Adapt<SysDictData>());
		}

		/// <summary>
		/// 删除字典值
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("删除字典值")]
		public async Task DeleteDictData(DeleteDictDataInput input)
		{
			await _sysDictDataManager.DeleteDictData(input.Id);
		}

		/// <summary>
		/// 获取字典值详情
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("获取字典值详情")]
		public async Task<SysDictData> GetDetail([FromQuery] DictDataInput input)
		{
			return await _sysDictDataManager.GetDetail(input.Id);
		}

		/// <summary>
		/// 修改字典值状态
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("修改字典值状态")]
		public async Task SetStatus(DictDataInput input)
		{
			await _sysDictDataManager.SetStatus(input.Id,input.Status);
		}

		/// <summary>
		/// 根据字典类型编码获取字典值集合
		/// </summary>
		/// <param name="code"></param>
		/// <returns></returns>
		[DisplayName("根据字典类型编码获取字典值集合")]
		public async Task<List<SysDictData>> GetDataListFromCode(string code)
		{
			return await _sysDictTypeManager.GetDataList(code);
		}

		/// <summary>
		/// 根据查询条件获取字典值集合
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("根据查询条件获取字典值集合")]
		public async Task<List<SysDictData>> GetDataList([FromQuery] QueryDictDataInput input)
		{
			return await _sysDictTypeManager.GetDataList(input.Code, input.Status);
		}
	}
}
